layui.define(['jquery','form'], function (exports) {
	"use strict";
	var $ = layui.jquery,form=layui.form,object = {
		c: {data:[]}, // 配置项
		f: function (c) { // 数据初始化
			var s=new Date().getTime(),t = this;
			t.c.id = c.id?c.id:'simple_table_THR_CanvassApply';
			t.c.tableId = c.tableelem?c.tableelem:'table-'+s;
			t.c.data = c.data; // 数据
			//将表单数据带入js
			t.c.formObj = c.formObj;
			console.log('data',t.c.data);
			/**自定义的字段，是否流转中**/
			t.c.onProcess = c.onProcess;

			//复选框选中，存放行号
			t.c.checkedIndex = [];

			//多文件上传需要
			t.c.id_form = 'id_form_' + s;
			t.c.urlUpload = 'https://file.mini-ease.com/api/outer/upload/uploadForERP_1_0';

		},
        load:function () { // 加载控件
        	var h = ``
        		+ `<div class="layui-form layui-form-item" lay-filter="` + this.id + `" style="background-color: #ffffff;padding-top: 10px;padding-bottom: 10px;">`
    				+ `<label style="font-weight: 700;font-size: 18px; padding: 15px;">列表信息</label>`
        		+ `</div>`;

			if(this.c.onProcess == 0) {
				h += `<div class="layui-table-tool" style="padding-top: 0; min-height: 0; background-color: #ffffff;width: auto;">`
					+ `<div class="layui-table-tool-temp">`
					+ `<div class="layui-btn-container">`
					+ `<a class="layui-btn layui-btn-normal layui-btn-sm " lay-event="event-to-select" ><i class="iconfont icon-add-btn"></i>新增</a>`
					+ `<a class="layui-btn layui-btn-danger layui-btn-sm " lay-event="event-to-del" ><i class="layui-icon layui-icon-delete"></i>删除</a>`
					+ `</div>`
					+ `</div>`

					+ `</div>`
			}
			//多文件上传需要->id="` + this.c.id_form + `"
			h+= `<div class="layui-form layui-form-item" id="` + this.c.id_form + `"  pane>`
				+ `<div id="`+this.c.tableId+`">`
				+ this.loadTable()
				+ `</div>`
				+ `</div>`
				+ `</div>`;
			$('#'+this.c.id).html(h);
			this.listenBtn();
			this.listenBtnByTd();
        },
        loadTable:function () { // 加载表格
            return ``
        	+ `<div class="layui-table-box">`
        		+ `<div class="layui-table-header" style="height: 300px; max-height: 300px; overflow: auto; background-color: #ffffff;">`
	            	+ `<table cellspacing="0" cellpadding="0" border="0" class="layui-table layui-form" lay-skin="grid" lay-even="false" style="margin: 0;">`
	            		+ `<thead>`
	            			+ this.loadTableOfThead()
	            		+ `</thead>`
	            		+ `<tbody>` + this.loadTableOfTbody()+`</tbody>`
	        		+ `</table>`
        		+ `</div>`
    		+ `</div>`;



        },
        loadTableOfThead:function () { // 加载表头
            var h = `<thead>`;
            h +=`<tr>`;
			h += `<th style="display: none;">id</th>`;
			h += `<th style="width:1.9%; text-align: center; color: #000000;padding: 0 !important;">
							<input type="checkbox" id="checkAll" lay-skin="primary" lay-filter="checkAll">
						</th>`;
			h += `<th class="white_space_nowrap" style="width:5%; text-align: center; color: #000000;">公司名</th>`;
			h += `<th class="white_space_nowrap" style="width:5%; text-align: center; color: #000000;"><font class="f_red">*</font>公司简称</th>`;
			h += `<th class="white_space_nowrap" style="width:5%; text-align: center; color: #000000;">公司属性</th>`;
			h += `<th class="white_space_nowrap" style="width:5%; text-align: center; color: #000000;">税号</th>`;
			h += `<th class="white_space_nowrap" style="width:5%; text-align: center; color: #000000;">法人</th>`;
			h += `<th class="white_space_nowrap" style="width:5%; text-align: center; color: #000000;">法人联系方式</th>`;
			h += `<th class="white_space_nowrap" style="width:5%; text-align: center; color: #000000;">法人身份证</th>`;
			h += `<th class="white_space_nowrap" style="width:5%; text-align: center; color: #000000;">开户名</th>`;
			h += `<th class="white_space_nowrap" style="width:5%; text-align: center; color: #000000;">开户行</th>`;
			h += `<th class="white_space_nowrap" style="width:5%; text-align: center; color: #000000;">银行账号</th>`;
			h += `<th class="white_space_nowrap" style="width:5%; text-align: center; color: #000000;">机构名称</th>`;
			h += `<th class="white_space_nowrap" style="width:5%; text-align: center; color: #000000;">上级公司编码</th>`;
			h += `<th class="white_space_nowrap" style="width:5%; text-align: center; color: #000000;">上级公司简称</th>`;
			h += `<th class="white_space_nowrap" style="width:5%; text-align: center; color: #000000;">招商类型</th>`;
			h += `<th class="white_space_nowrap" style="width:5%; text-align: center; color: #000000;">费用标准</th>`;
			h += `<th class="white_space_nowrap" style="width:5%; text-align: center; color: #000000;">平台</th>`;
			h += `<th class="white_space_nowrap" style="width:5%; text-align: center; color: #000000;">区域</th>`;
			h += `<th class="white_space_nowrap" style="width:5%; text-align: center; color: #000000;">国家</th>`;
			h += `<th class="white_space_nowrap" style="width:5%; text-align: center; color: #000000;">链接码</th>`;
			h += `<th class="white_space_nowrap" style="width:5%; text-align: center; color: #000000;">平台经理</th>`;
			h += `<th class="white_space_nowrap" style="width:5%; text-align: center; color: #000000;">注册要求</th>`;
			h += `<th class="white_space_nowrap" style="width:5%; text-align: center; color: #000000;">营业执照</th>`;
			h += `<th class="white_space_nowrap" style="width:5%; text-align: center; color: #000000;">合作协议</th>`;

            h += `</tr>`;
            h + `</thead>`;
			return h;
        },
        loadTableOfTbody:function () { // 加载表tbody
        	var t = this;
        	var h = `<tbody id="tbody">`;
            for(var i=0;i<t.c.data.length;i++){
				h += `<tr id="table_th_`+i+`">`;
				h += t.loadTableTdOfTbody(t.c.data[i],i);

				h+= `</tr>`;
            }
            h += `</tbody>`;
			return h;
        },
		loadTableTdOfTbody:function (data,i) { // 加载表格行
			var t = this;
			var h = `<td style="display: none; text-align:center; padding: 0;">` + data.id + `</td>`;
			h += `<td style="text-align:center;padding:0;width:1.9%;">
					<input type="checkbox" class="chBox"  lay-skin="primary" data-index="` + i + `"  lay-filter="checkBoxOne">
					</td>`;
			if(this.c.onProcess == 0) {//可编辑
				// h += `<td style="width:5%;text-align:center; padding: 0;">` + (data.vgsmc!=undefined?data.vgsmc:'') + `</td>`;
				// h += `<td style="width:5%;text-align:center; padding: 0;">` + (data.vgsjc!=undefined?data.vgsjc:'') + `</td>`;
				h += `<td style="width:5%;text-align:center;padding:0;"><input type="text" maxlength="20"  class="text_align_center layui-input"  lay-filter="_input"  data-type="vgsmc" value="` + (data.vgsmc!=undefined?data.vgsmc:'') + `" data-index="` + i + `"></td>`;
				h += `<td style="width:5%;text-align:center;padding:0;"><input type="text" maxlength="20"  class="text_align_center layui-input"  lay-filter="_input"  data-type="vgsjc" value="` + (data.vgsjc!=undefined?data.vgsjc:'') + `" data-index="` + i + `"></td>`;
				h += `<td style="width:5%;text-align:center; padding: 0;">运营公司</td>`;
				h += `<td style="width:5%;text-align:center;padding:0;"><input type="text" maxlength="20"  class="text_align_center layui-input"  lay-filter="_input"  data-type="vgsSh" value="` + (data.vgsSh!=undefined?data.vgsSh:'') + `" data-index="` + i + `"></td>`;
				h += `<td style="width:5%;text-align:center;padding:0;"><input type="text" maxlength="20"  class="text_align_center layui-input"  lay-filter="_input"  data-type="corporation" value="` + (data.corporation!=undefined?data.corporation:'') + `" data-index="` + i + `"></td>`;
				h += `<td style="width:5%;text-align:center;padding:0;"><input type="text" maxlength="20"  class="text_align_center layui-input"  lay-filter="_input"  data-type="costTelephone" value="` + (data.costTelephone!=undefined?data.costTelephone:'') + `" data-index="` + i + `"></td>`;
				h += `<td style="width:5%;text-align:center;padding:0;"><input type="text" maxlength="20"  class="text_align_center layui-input"  lay-filter="_input"  data-type="vgsFrId" value="` + (data.vgsFrId!=undefined?data.vgsFrId:'') + `" data-index="` + i + `"></td>`;
				h += `<td style="width:5%;text-align:center;padding:0;"><input type="text" maxlength="20"  class="text_align_center layui-input"  lay-filter="_input"  data-type="accountName" value="` + (data.accountName!=undefined?data.accountName:'') + `" data-index="` + i + `"></td>`;
				h += `<td style="width:5%;text-align:center;padding:0;"><input type="text" maxlength="20"  class="text_align_center layui-input"  lay-filter="_input"  data-type="openingBank" value="` + (data.openingBank!=undefined?data.openingBank:'') + `" data-index="` + i + `"></td>`;
				h += `<td style="width:5%;text-align:center;padding:0;"><input type="text" maxlength="20"  class="text_align_center layui-input"  lay-filter="_input"  data-type="bankAccount" value="` + (data.bankAccount!=undefined?data.bankAccount:'') + `" data-index="` + i + `"></td>`;
				h += `<td style="text-align:center; padding: 0;"><input type="text" class="layui-input" value="` + (data.institutionName ? data.institutionName : '') + `" readonly="readonly"><i style="position: absolute; right: 2px; top:0px; height: 30px; line-height: 30px; width: 25px;" class="layui-icon layui-icon-more" data-type="institutionName" data-index="` + i + `" lay-filter="buttontextMode1"></i></td>`;
				h += `<td style="width:5%;text-align:center; padding: 0;">` + (data.vgsBmp!=undefined?data.vgsBmp:'') + `</td>`;
				h += `<td style="width:5%;text-align:center; padding: 0;">` + (data.vgsJcp!=undefined?data.vgsJcp:'') + `</td>`;
				h += `<td style="text-align:center; padding: 0;">`
					+ `<select id="investType" style="text-align: center" name="investType"  lay-filter="buttontextModelSel"  data-type="investType"` + `data-index="` + i + `">`;
				h += `<option value="" >请选择</option>
								<option value="0" `+(data.investType == '0'?`selected`:``)+`>首店</option>
								<option value="1" `+(data.investType == '1'?`selected`:``)+`>次店</option>
								<option value="2" `+(data.investType == '2'?`selected`:``)+`>特殊店</option>`;
				h +=`</select>`+
					`</td>`;
				h += `<td style="width:5%;text-align:center;padding:0;"><input type="text" maxlength="20"  class="text_align_center layui-input"  lay-filter="_input"  data-type="costStandard" value="` + (data.costStandard!=undefined?data.costStandard:'') + `" data-index="` + i + `"></td>`;
				h += `<td style="width:5%;text-align:center; padding: 0;">Amazon</td>`;
				h += `<td style="text-align:center; padding: 0;"><input type="text" class="layui-input" value="` + (data.region ? data.region : '') + `" readonly="readonly"><i style="position: absolute; right: 2px; top:0px; height: 30px; line-height: 30px; width: 25px;" class="layui-icon layui-icon-more" data-type="region" data-index="` + i + `" lay-filter="buttontextMode3"></i></td>`;
				h += `<td style="width:5%;text-align:center; padding: 0;">` + (data.country!=undefined?data.country:'') + `</td>`;

				h +='<td style="width:5%;text-align:center;padding:0;"><div class="layui-table-link upload_files'+i+'" style="cursor: pointer;" >' +
					'<div style="float:left;width: 82%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">' +
					 (data.linCode==undefined?'':(data.linCode.length>20?data.linCode.substring(0, 20)+'...':data.linCode)) +
					' </div>' +
					'<div style="float:right;width: 17%;"  title="点击上传" data-index="' + i + '"  lay-filter="upLoadFile">' +
					'<i class="layui-icon layui-icon-upload" style="float: right;" ></i>' +
					'</div>' +
					'</div></td>';

                                /*h += '<td style="width:5%;text-align:center;padding:0;">'+
                                        '<input type="text" class="text_align_center layui-input cannot_edit upload_files" lay-filter="upLoadFile" title="点击上传" data-type="linCode" value="' + (data.linCode!=undefined?data.linCode:'') + '" readonly data-index="' + i + '">'+
                                    '</td>';

                                 */
				h += `<td style="width:5%;text-align:center;padding:0;"><input type="text" maxlength="20"  class="text_align_center layui-input"  lay-filter="_input"  data-type="platformManager" value="` + (data.platformManager!=undefined?data.platformManager:'') + `" data-index="` + i + `"></td>`;
				h += `<td style="width:5%;text-align:center;padding:0;"><input type="text" maxlength="20"  class="text_align_center layui-input"  lay-filter="_input"  data-type="registrationRequire" value="` + (data.registrationRequire!=undefined?data.registrationRequire:'') + `" data-index="` + i + `"></td>`;
				h +='<td style="width:5%;text-align:center;padding:0;">' +
					'<input type="text"  value="' + (data.businesslicense?data.businesslicense : '0个附件') + '" autocomplete="off" class="layui-input height_30 height_30 cannot_edit" readonly data-filter="_filter_input_file_multy" data-source-code="businesslicense" data-source-type="22" data-source-id="' + data.id + '" data-index="' + i + '">'+
					'</td>';
				h +='<td style="width:5%;text-align:center;padding:0;">' +
					'<input type="text"  value="' + (data.cooperateAgreement?data.cooperateAgreement : '0个附件') + '" autocomplete="off" class="layui-input height_30 height_30 cannot_edit" readonly data-filter="_filter_input_file_multy" data-source-code="cooperateAgreement" data-source-type="23" data-source-id="' + data.id + '"data-index="' + i + '">'+
					'</td>';
			}else {//不可编辑
				h += `<td style="width:5%;text-align:center; padding: 0;">` + (data.vgsmc!=undefined?data.vgsmc:'') + `</td>`;
				h += `<td style="width:5%;text-align:center; padding: 0;">` + (data.vgsjc!=undefined?data.vgsjc:'') + `</td>`;
				h += `<td style="width:5%;text-align:center; padding: 0;">运营公司</td>`;
				h += `<td style="width:5%;text-align:center; padding: 0;">` + (data.vgsSh!=undefined?data.vgsSh:'') + `</td>`;
				h += `<td style="width:5%;text-align:center; padding: 0;">` + (data.corporation!=undefined?data.corporation:'') + `</td>`;
				h += `<td style="width:5%;text-align:center; padding: 0;">` + (data.costTelephone!=undefined?data.costTelephone:'') + `</td>`;
				h += `<td style="width:5%;text-align:center; padding: 0;">` + (data.vgsFrId!=undefined?data.vgsFrId:'') + `</td>`;
				h += `<td style="width:5%;text-align:center; padding: 0;">` + (data.accountName!=undefined?data.accountName:'') + `</td>`;
				h += `<td style="width:5%;text-align:center; padding: 0;">` + (data.openingBank!=undefined?data.openingBank:'') + `</td>`;
				h += `<td style="width:5%;text-align:center; padding: 0;">` + (data.bankAccount!=undefined?data.bankAccount:'') + `</td>`;
				h += `<td style="width:5%;text-align:center; padding: 0;">` + (data.institutionName!=undefined?data.institutionName:'') + `</td>`;
				h += `<td style="width:5%;text-align:center; padding: 0;">` + (data.vgsBmp!=undefined?data.vgsBmp:'') + `</td>`;
				h += `<td style="width:5%;text-align:center; padding: 0;">` + (data.vgsJcp!=undefined?data.vgsJcp:'') + `</td>`;
				var investType  ="";
				if(data.investType == '0'){
					investType = "首店";
				}else if(data.investType == '1'){
					investType = "次店";
				}else if(data.investType == '2') {
					investType = "特殊店";
				}
				h += `<td style="width:5%;text-align:center; padding: 0;">` + investType + `</td>`;
				h += `<td style="width:5%;text-align:center; padding: 0;">` + (data.costStandard!=undefined?data.costStandard:'') + `</td>`;
				h += `<td style="width:5%;text-align:center; padding: 0;">Amazon</td>`;
				h += `<td style="width:5%;text-align:center; padding: 0;">` + (data.region!=undefined?data.region:'') + `</td>`;
				h += `<td style="width:5%;text-align:center; padding: 0;">` + (data.country!=undefined?data.country:'') + `</td>`;
				h += `<td style="width:5%;text-align:center; padding: 0;">` + (data.linCode!=undefined?data.linCode:'') + `</td>`;
				// h +='<td style="width:5%;text-align:center;padding:0;"><div class="layui-table-link upload_files'+i+'" style="cursor: pointer;" >' +
				// 	'<div style="float:left;width: 82%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">' +
				// 	(data.linCode==undefined?'':(data.linCode.length>20?data.linCode.substring(0, 20)+'...':data.linCode)) +
				// 	' </div>' +
				// 	'<div style="float:right;width: 17%;"  title="点击上传" data-index="' + i + '"  lay-filter="upLoadFile">' +
				// 	'<i class="layui-icon layui-icon-upload" style="float: right;" ></i>' +
				// 	'</div>' +
				// 	'</div></td>';
				h += `<td style="width:5%;text-align:center; padding: 0;">` + (data.platformManager!=undefined?data.platformManager:'') + `</td>`;
				h += `<td style="width:5%;text-align:center; padding: 0;">` + (data.registrationRequire!=undefined?data.registrationRequire:'') + `</td>`;
				//h += `<td style="width:5%;text-align:center; padding: 0;">` + (data.vdfilesName!=undefined?data.vdfilesName:'') + `</td>`;
				//多文件上传
				h +='<td style="width:5%;text-align:center;padding:0;">' +
					'<input type="text"  value="' + (data.businesslicense?data.businesslicense : '0个附件') + '" autocomplete="off" class="layui-input height_30 height_30 cannot_edit" readonly data-filter="_filter_input_file_multy" data-source-code="businesslicense" data-source-type="22" data-source-id="' + data.id + '" data-index="' + i + '">'+
					'</td>';
				h +='<td style="width:5%;text-align:center;padding:0;">' +
					'<input type="text"  value="' + (data.cooperateAgreement?data.cooperateAgreement : '0个附件') + '" autocomplete="off" class="layui-input height_30 height_30 cannot_edit" readonly data-filter="_filter_input_file_multy" data-source-code="cooperateAgreement" data-source-type="23" data-source-id="' + data.id + '"data-index="' + i + '">'+
					'</td>';
			}

			return h;
		},
		listenBtn:function () {// 头部按钮监听
			var t = this;
			// 监听“新增”按钮
			$('a[lay-event="event-to-select"]').on('click',function (e) {
				var rowCurrent = {};
				rowCurrent.id = null;
				rowCurrent.userId = '保存后自动生成';
				rowCurrent.vgsmc = "";
				rowCurrent.vgsjc = "";
				rowCurrent.companyattributes = "运营公司";
				rowCurrent.vgsSh = "";
				rowCurrent.vgsFrId = "";
				rowCurrent.accountName = "";
				rowCurrent.openingBank = "";
				rowCurrent.bankAccount = "";
				rowCurrent.institutionName = "";
				rowCurrent.vgsBmp = "";
				rowCurrent.vgsJcp = "";
				rowCurrent.investType = "";
				rowCurrent.corporation = "";
				rowCurrent.costTelephone = "";
				rowCurrent.costStandard = "";
				rowCurrent.platform = "Amazon";
				rowCurrent.region = "";
				rowCurrent.country = "";
				rowCurrent.linCode = "";
				rowCurrent.platformlanager = "";
				rowCurrent.platform = "";
				rowCurrent.businesslicense = "";
				rowCurrent.cooperateAgreement = "";
				t.addRow(rowCurrent);
			});

			//全选
			layui.form.on('checkbox(checkAll)', function(data){
				var elem = data.elem;
				$(".chBox").prop("checked", elem.checked);
				var checkedIndex = [];
				$(".chBox").each(function(k, v){
					if ($(v).is(':checked')) {
						checkedIndex.push($(v).attr('data-index'));
					}
				});
				t.c.checkedIndex = checkedIndex;
				//console.log('t.c.checkedIndex',t.c.checkedIndex);
				layui.form.render();
			});

			// 列表里的小选择框点击
			layui.form.on('checkbox(checkBoxOne)', function(data){
				var elem = data.elem;
				//console.log('elem',elem);
				if ($(".chBox").not('input:checked').length) {
					$('#checkAll').prop("checked", false);
				} else {
					$('#checkAll').prop("checked", true);
				}
				var checkedIndex = [];
				$(".chBox").each(function(k, v){
					if ($(v).is(':checked')) {
						checkedIndex.push($(v).attr('data-index'));
					}
				});
				t.c.checkedIndex = checkedIndex;
				layui.form.render();
			});

			// 监听“删除”按钮
			$('a[lay-event="event-to-del"]').on('click',function (e) {
				var checkedIndexList = t.c.checkedIndex;
				console.log('t.c.checkedIndex',t.c.checkedIndex);
				if (checkedIndexList.length ==0 || checkedIndexList==null){
					return layer.msg("请至少选择一条要删除的数据!");
				}


					var oldData = [];
					for (var i = 0; i < t.c.data.length; i++) {
						var isOld = false;
						for (var j = 0; j < checkedIndexList.length; j++) {
							if(i == checkedIndexList[j] && t.c.data[i].id!=null){
								isOld = true;
							}
						}
						if(isOld){
							oldData.push(t.c.data[i].id);
						}
					}

					if(oldData.length>0){
						//var idJsonStr = JSON.stringify(oldData);
						t.delYes(oldData,checkedIndexList);
					}else{
						var newData = [];
						for (var i = 0; i < t.c.data.length; i++) {
							var isDel = false;
							for (var j = 0; j < checkedIndexList.length; j++) {
								if(i == checkedIndexList[j]){
									isDel = true;
								}
							}
							if(!isDel){
								newData.push(t.c.data[i]);
							}
						}
						t.c.data = newData;
						$('#' + t.c.id).empty();
						return t.reload(t.c);
					}

				//}, function () {});//点击取消的回调
			});


		},
		listenBtnByTd:function () { // 添加监听
			var t = this;
			var domTable = $('#' + t.c.tableId);
			//先移除监听、再添加监听
			// $("i").off("click");
			//监听时间选择
			layui.laydate.render({
				elem: '.paymentTimeSet',
				type: 'date',
				done: function(value, date, endDate){
					var indexOfRow =  $(this.elem).attr('data-index');
					t.c.data[indexOfRow].birthday = value;
					var h = t.loadTableTdOfTbody(t.c.data[Number(indexOfRow)],Number(indexOfRow));
					$('#table_th_' + indexOfRow).html(h);
					t.listenBtnByTd();
				}
			});

			domTable.find('div[lay-filter="upLoadFile"]').off("click");
			//监听文件上传
			domTable.find('div[lay-filter="upLoadFile"]').on('click',function (e) {
				var indexOfRow = $(this).attr('data-index');
				console.log("indexOfRow",indexOfRow);
				var inst = layui.upload.render({
					elem: '.upload_files'+indexOfRow,
					url: 'https://file.mini-ease.com/api/outer/upload/uploadForERP_1_0',
					multiple: false,
					accept: 'file',
					auto:true,
					done: function(res){
						t.c.data[indexOfRow].linCode = res.data.filePath;
						var h = t.loadTableTdOfTbody(t.c.data[Number(indexOfRow)],Number(indexOfRow));
						$('#table_th_' + indexOfRow).html(h);
						t.listenBtnByTd();
					},
				});

			});

			domTable.find('i[lay-filter="buttontextMode1"]').off("click");
			// 监听弹出框
			domTable.find('i[lay-filter="buttontextMode1"]').on('click',function (e) {
				var indexOfRow = $(this).attr('data-index');
				layui.YsModal.init({modalKey: 'TS_OperateOrg', colCode: indexOfRow, parentObj: t, extraData: {useIn: 'buttontextMode1'}})
			});
			domTable.find('i[lay-filter="buttontextMode2"]').off("click");
			// 监听弹出框
			domTable.find('i[lay-filter="buttontextMode2"]').on('click',function (e) {
				var indexOfRow = $(this).attr('data-index');
				layui.YsModal.init({modalKey: 'THR_OperateCompanyApply', colCode: indexOfRow, parentObj: t, extraData: {useIn: 'buttontextMode2'}})
			});
			domTable.find('i[lay-filter="buttontextMode3"]').off("click");
			// 监听弹出框
			domTable.find('i[lay-filter="buttontextMode3"]').on('click',function (e) {
				var indexOfRow = $(this).attr('data-index');
				layui.YsModal.init({modalKey: 'TB_Site', colCode: indexOfRow, parentObj: t, extraData: {useIn: 'buttontextMode3'}})
			});
			// 绑定选择框(转换)的值变化提交事件
			layui.form.on('select(buttontextModelSel)', function(data){
				var indexOfRow = $(data.elem).attr('data-index');
				t.c.data[indexOfRow].investType = data.value;
				if(data.value=='0'){
					t.c.data[indexOfRow].costStandard = 1499;
				}
				else if(data.value=='1'){
					t.c.data[indexOfRow].costStandard = 599;
				}
				else if(data.value=='2'){
					t.c.data[indexOfRow].costStandard = 0;
				}
				$('#' + t.c.id).empty();
				return t.reload(t.c);
			});

			// 绑定选择框(转换)的值变化提交事件
			layui.form.on('select(buttontextModelSelByInvestType)', function(data){
				var indexOfRow = $(data.elem).attr('data-index');
				t.c.data[indexOfRow].education = data.value;
				var h = t.loadTableTdOfTbody(t.c.data[Number(indexOfRow)],Number(indexOfRow));
				$('#table_th_' + indexOfRow).html(h);
				t.listenBtnByTd();
			});

			//监听表格中的input框的值修改
			domTable.find('input[lay-filter="_input"]').on('blur',function (e) {
				var indexOfRow = $(this).attr('data-index');
				var dataType = $(this).attr('data-type');
				var priceIn = 0;
				for (var i = 0; i < t.c.data.length; i++) {
					if(i ==  Number(indexOfRow)){
						if (dataType == 'vgsSh'){
							t.c.data[i].vgsSh = e.delegateTarget.value
						}else if (dataType == 'corporation'){
							t.c.data[i].corporation = e.delegateTarget.value
						}else if (dataType == 'vgsFrId'){
							t.c.data[i].vgsFrId = e.delegateTarget.value
						}else if (dataType == 'accountName'){
							t.c.data[i].accountName = e.delegateTarget.value
						}else if (dataType == 'openingBank'){
							t.c.data[i].openingBank = e.delegateTarget.value
						}else if (dataType == 'bankAccount'){
							t.c.data[i].bankAccount = e.delegateTarget.value
						}else if (dataType == 'platformManager'){
							t.c.data[i].platformManager = e.delegateTarget.value
						}else if (dataType == 'registrationRequire'){
							t.c.data[i].registrationRequire = e.delegateTarget.value
						}else if (dataType == 'vgsmc'){
							t.c.data[i].vgsmc = e.delegateTarget.value
						}else if (dataType == 'vgsjc'){
							t.c.data[i].vgsjc = e.delegateTarget.value
						}else if (dataType == 'costTelephone'){
							t.c.data[i].costTelephone = e.delegateTarget.value
						}
					}
				}
				var h = t.loadTableTdOfTbody(t.c.data[Number(indexOfRow)],Number(indexOfRow));
				$('#table_th_' + indexOfRow).html(h);
				t.listenBtnByTd();
			});
			//多文件上传
			t.listenFormOfFileMulty();
			// 表单控件重新加载
			form.render();
		},

		matchValuesAfterModalSelectRadio:function (colCode, rowSelected, extraData) { // 单选框选中数据后，匹配表单数值
			var t = this;
			console.log("rowSelected",rowSelected);
			if(extraData.useIn == 'buttontextMode1') {
				t.c.data[colCode].institutionId= rowSelected.id;
				t.c.data[colCode].institutionName= rowSelected.name;
				t.c.data[colCode].vgsBmp= rowSelected.parentVgsbm;
				t.c.data[colCode].vgsJcp= rowSelected.parentVgsjc;
			}
			if(extraData.useIn == 'buttontextMode2') {
				t.c.data[colCode].vgsbm = rowSelected.vgsbm;
				t.c.data[colCode].vgsmc = rowSelected.vgsmc;
				t.c.data[colCode].vgsjc = rowSelected.vgsjc;
			}
			if(extraData.useIn == 'buttontextMode3') {
				t.c.data[colCode].region = rowSelected.regionName;
				t.c.data[colCode].country = rowSelected.countryName;
				//t.c.data[colCode].amazonRegionItemId = rowSelected.itemId;
				t.c.data[colCode].siteId = rowSelected.id;
			}

			var h = t.loadTableTdOfTbody(t.c.data[Number(colCode)],Number(colCode));
			$('#table_th_' + colCode).html(h);
			t.listenBtnByTd();
		},
		//确定删除
		delYes:function(spId,checkedIndexList){
			var t = this;
			var c = this.c;
			var loadIndex = layer.load(2);
			$.ajax({
				url: '/api/inter/thrCanvassApply/toDelItem',
				data: "list="+spId,
				type: 'POST',
				async: true,
				success: function (result) {
					console.log('result',result);
					if(result.code==0){
						layer.close(loadIndex);
						layer.msg("操作成功", {icon: 1});
						//表格重载
						var newData = [];
						for (var i = 0; i < c.data.length; i++) {
							var isDel = false;
							for (var j = 0; j < checkedIndexList.length; j++) {
								if(i==checkedIndexList[j]){
									isDel = true;
								}
							}
							if(!isDel){
								newData.push(c.data[i]);
							}
						}
						c.data = newData;
						$('#' + c.id).empty();
						return t.reload(c);
					}else {//失败
						layer.close(loadIndex);
						layer.msg(result.msg, {icon: 2});
					}
				},
				error: function () {
					layer.close(loadIndex);
					layer.msg("删除失败，请稍后再试！", {icon: 2});
				}
			});
		},
		removeRow:function(index) { // 重新加载表格
			var t = this;
			t.c.data.splice(index, 1);
			return t.reload(t.c);
		},
		reloadTable:function () { // 重新加载表格
			$('#'+this.c.tableId).html(this.loadTable());
			this.listenBtn();
			t.listenBtnByTd();
		},
		getData:function () {
			return this.c.data;
		},
		init:function (c) {
			this.f(c);
			this.load();
			return object;
		},
		reload:function (c) {
			c.data = this.c.data;
			$('#' + this.c.id).empty();
			return this.init(c);
		},
		addRow:function (row) {
			var c = this.c;
			var t = this;
			c.data.push(row);
			var h =  `<tr id="table_th_`+(c.data.length-1)+`">`;
			h += t.loadTableTdOfTbody(row,c.data.length-1);
			h+= `</tr>`;
			$('#tbody').append(h);
			t.listenBtnByTd();
			//t.listenBtnByTdYsModal();
		},
		addRows:function (rows) {
			var c = this.c;
			for (var i = 0; i < rows.length; i++) {
				c.data.push(rows[i]);
			}
			$('#' + c.id).empty();
			return this.reload(c);
		},
		editRow:function (index, row) {
			var c = this.c;
			c.data[index] = row;
			$('#' + c.id).empty();
			return this.reload(c);
		},
		editRowOfAttr:function (index, row) {
			var c = this.c;
			for(var key in row){
				c.data[index][key] = row[key]
			}
			$('#' + c.id).empty();
			return this.reload(c);
		},
		reloadRows:function (rows) {
			var c = this.c;
			c.data = rows;
			return this.reload(c);
		},
		//重写toFixed方法
		toFixed:function(number, precision) {
			if (Number.isInteger(Number(number))) {
				return number;
			}
			number = Math.round(+number + 'e' + precision) / Math.pow(10, precision) + '';
			let s = number.split('.');
			if ((s[1] || '').length < precision) {
				s[1] = s[1] || '';
				s[1] += new Array(precision - s[1].length).fill('0').join('');
			}
			return s.join('.');
		},
		//多文件上传
		listenFormOfFileMulty:function () { // 添加监听-多文件框
			var t = this;
			var domForm = $('#' + t.c.id_form);
			var domTable = $('#' + t.c.tableId);


			//先移除监听、再添加监听
			domTable.find('input[data-filter="_filter_input_file_multy"]').off("click");

			// 初始化多文件上传控件
			domTable.find('input[data-filter="_filter_input_file_multy"]').on('click',function (e) {
				var dom = this;
				var indexOfRow = $(this).attr('data-index');
				//多文件上传

				var fileCount =null;
				var sourceId = $(this).attr('data-source-id');
				var sourceType = $(this).attr('data-source-type');
				var sourceCode = $(this).attr('data-source-code');
				if(sourceType=='22'){
					 fileCount = t.c.data[indexOfRow].businesslicense!=undefined?t.c.data[indexOfRow].businesslicense:"0个附件";
				}
				if(sourceType=='23'){
					 fileCount = t.c.data[indexOfRow].cooperateAgreement!=undefined?t.c.data[indexOfRow].cooperateAgreement:"0个附件";
				}
				var where = {
					sourceId: sourceId,
					sourceType: sourceType,
					sourceCode: sourceCode
				}
				if (sourceId == 'undefined' || sourceId == null || sourceId == 'null') {
					alert('表单尚未保存，无法操作上传');
					return;
				}

				t.c.id_modal_multy_file_panel = 'id_modal_multy_file_panel_' + (new Date().getTime()); // 生成容器ID
				t.c.id_modal_multy_file_grid = 'id_modal_multy_file_grid_' + (new Date().getTime()); // 生成表格ID
				var content =
					`<div class="ysui-col" style="width: 100%;" id="` + t.c.id_modal_multy_file_panel + `">`
					+ `<table class="layui-hide" id="` + t.c.id_modal_multy_file_grid + `" lay-filter="` + t.c.id_modal_multy_file_grid + `"></table>`
					+ `<script type="text/html" id="templet_index_no">`
					+ `{{d.LAY_TABLE_INDEX+1}}`
					+ `</script>`
					+ `<script type="text/html" id="_multy_file_grid_toolbar">`
					+ `<div class="layui-btn-container">`;
				if(t.c.onProcess == 0) {
					content += `<a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="_multy_file_to_add"><i class="iconfont icon-add-btn"></i>新增</a>`
					+ `<a class="layui-btn layui-btn-normal layui-btn-sm layui-btn-danger" lay-event="_multy_file_batch_delete"><i class="iconfont icon-delete"></i>删除</a>`;
				}
				content += `</div>`
					+ `</script>`
					+ `<script type="text/html" id="templet_script_for_multy_file">`
					+ `<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="_multy_file_single_download"><i class="layui-icon layui-icon-download-circle" title="下载"></i></a>`;
				if(t.c.onProcess == 0) {
					content += `<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="_multy_file_single_delete"><i class="layui-icon layui-icon-close" title="删除"></i></a>`;
				}
				content += `</script>`
					+ `</div>`;
				// + t.loadScriptTPL();

				var w=($(window).width()*0.8);
				var h=($(window).height() - 50);
				layer.open({
					type: 1,
					area: [w + 'px', h + 'px'],
					fix: false,
					//不固定
					maxmin: true,
					shade: 0.6,
					title: '附件列表',
					content: content,
					btn: ['确定', '关闭'],
					//点击弹层外区域关闭
					shadeClose: true,
					yes: function (index) {// 点击“确定”，执行的回调函数
						//多文件上传

						if(sourceType=='22'){
							t.c.data[indexOfRow].businesslicense = fileCount;
						}
						if(sourceType=='23'){
							t.c.data[indexOfRow].cooperateAgreement = fileCount;
						}
						var h = t.loadTableTdOfTbody(t.c.data[Number(indexOfRow)],Number(indexOfRow));
						$('#table_th_' + indexOfRow).html(h);
						t.listenBtnByTd();
						layer.close(index);

					},
					btn2: function(index, layero){
						layer.close(index);
					},
					success: function(layero, index) {
						layui
							.use(['form', 'table'], function(){
								var table = layui.table;
								var form = layui.form;
								var $ = layui.jquery;

								// 创建渲染实例
								table.render({
									elem: '#' + t.c.id_modal_multy_file_grid
									,url: '/api/inter/tbFileInfo/search'
									,toolbar: '#_multy_file_grid_toolbar'
									,defaultToolbar: [{
										title: '刷新页面'
										,layEvent: 'LAYTABLE_REFRESH'
										,icon: 'layui-icon-refresh'
									}]
									,height: 'full-240' // 最大高度减去其他容器已占有的高度差
									,limit : 50
									,limits : [50,100,200,500]
									,where: where
									,cellMinWidth: 150
									,page: true
									,request: {
										pageName: 'page',
										limitName: 'size'
									}
									,even: false // 开启隔行背景
									,cols: [ [
										{'title': '', 'type': 'checkbox', 'fixed': 'left', 'unresize': true, 'width': '70'},
										{'title': '文件名', 'field': 'preName', 'width': '180', 'align': 'center'},
										{'title': '大小', 'field': 'fileSize', 'width': '80', 'align': 'center'},
										{'title': '类型', 'field': 'sufName', 'width': '120', 'align': 'center'},
										{'title': '上传时间', 'field': 'createTime', 'width': '200', 'align': 'center'},
										{'title': '操作', 'field': 'ope', 'width': '240', 'align': 'center', templet: '#templet_script_for_multy_file'}
									] ]
									,done: function(objDone){
										$(dom).val(objDone.count + '个附件');
										fileCount = objDone.count + '个附件';
										// 绑定新增按钮-文件上传控件
										$('#' + t.c.id_modal_multy_file_panel).find('a[lay-event="_multy_file_to_add"]').each(function(index, domEle){
											var dom = this;
											var labelName = $(this).attr('label');
											layui.upload.render({
												elem: dom,
												url: t.c.urlUpload,
												multiple: true,
												accept: 'file',
												progress: function(n, elem){
													//dom.val(n + '%');
												},
												done: function(res, index, upload){
													if (res.code == 0) {
														console.log('res:',res);
														var fileName = res.data.fileName;
														var indexPeriod = fileName.indexOf('.');

														// 添加数据到附件表
														$.ajax({
															type: "POST",
															url: '/api/inter/tbFileInfo/add',
															data: {
																sourceType: sourceType,
																sourceId: sourceId,
																sourceCode: sourceCode,
																preName: indexPeriod >= 0 ? fileName.substring(0, indexPeriod) : fileName,
																sufName: indexPeriod >= 0 ? fileName.substring(indexPeriod + 1, fileName.length) : '',
																fileType: res.data.fileType,
																fileSize: res.data.fileSizeLong,
																filePath: res.data.filePath
															},
															success: function (data) {
																if (data.code == 0) {
																} else {
																	alert(data.msg);
																}
															}
														});
														return;
														var urlFile = res.data.filePath;
														domForm.find('img[label="' + labelName +'"]').attr('src', '/static/img/img_file.jpg');
														domForm.find('input[name="' + labelName +'"]').val(urlFile);
														domForm.find('button[label="' + labelName +'"]').show();
													}
												},
												allDone: function(obj){
													setTimeout(function(){
														layui.table.reload(t.c.id_modal_multy_file_grid, {
															page: {curr: 1},
															where: where
														});
													}, 1000);
												}
											});
										});
									}
									,error: function(res, msg){
										console.log(res, msg)
									}
								});
							});

						// 右侧工具栏事件
						layui.table.on('toolbar(' + t.c.id_modal_multy_file_grid + ')', function(obj){
							var id = obj.config.id;
							var checkStatus = layui.table.checkStatus(id);
							var datas = checkStatus.data;
							var othis = lay(this);

							switch(obj.event){
								case '_multy_file_batch_delete':
								{
									if(datas.length == 0) {
										layer.alert('尚未选中数据');
									} else {
										var ids = '';
										for(var i = 0 ;i < datas.length; i++){
											ids += datas[i].id + ',';
										}
										var indexOfLoading = layer.load(1, {
											shade: [0.5,'#000000'] //0.1透明度的白色背景
										});
										$.ajax({
											type: "POST",
											url: '/api/inter/tbFileInfo/deleteBatch',
											data: {ids: ids.substring(0, ids.length - 1)},
											success: function (res) {
												if (res.code == 0) {
													layer.msg(res.msg);
													layui.table.reload(t.c.id_modal_multy_file_grid,{
														page: {curr: 1},
														where: where
													})
												} else {
													alert(res.msg);
												}
												layer.close(indexOfLoading);
											}
										});
									}
									break;
								}
							};
						});

						// 表格内按钮点击事件
						layui.table.on('tool(' + t.c.id_modal_multy_file_grid + ')', function(obj){
							console.log(obj);
							switch(obj.event){
								case '_multy_file_single_download':
								{
									const xhr = new XMLHttpRequest();
									xhr.open('GET', obj.data.filePath);
									xhr.responseType = 'blob';
									xhr.onload = function() {
										const blob = xhr.response;
										const link = document.createElement('a');
										link.href = URL.createObjectURL(blob);
										link.download = obj.data.preName + (obj.data.sufName ? '.' + obj.data.sufName : '');
										link.target = "_blank"; // 可选，如果希望在新窗口中下载文件，请取消注释此行
										link.click();
									};
									xhr.send();
									layer.close(indexOfLoading);
									break;
								}
								case '_multy_file_single_delete':
								{
									layer.confirm('确定删除此附件？ ', {
										btn: ['确定','取消'] //按钮
									}, function(index){
										var indexOfLoading = layer.load(1, {
											shade: [0.5,'#000000'] //0.1透明度的白色背景
										});
										$.ajax({
											type: "POST",
											url: '/api/inter/tbFileInfo/delete',
											data: {id: obj.data.id},
											success: function (res) {
												if (res.code == 0) {
													layer.msg(res.msg);
													layui.table.reload(t.c.id_modal_multy_file_grid,{
														page: {curr: 1},
														where: where
													})
												} else {
													alert(res.msg);
												}
												layer.close(indexOfLoading);
											}
										});
									}, function(index){
										layer.close(index);
									});
									break;
								}
							};
						});
					}
				});
			});
		},
	};
	exports('simple_table_THR_CanvassApply', object);
});